package com.neusoft.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
import com.neusoft.elmboot.po.Food;
import com.neusoft.elmboot.po.User;

@Mapper
public interface FoodMapper {

	@Select("select * from food where businessId=#{businessId} order by foodId")
	public List<Food> listFoodByBusinessId(Integer businessId);

	@Select("select * from food where foodId=#{foodId}")
	public Food getFoodById(Integer foodId);
	
	@Insert("insert into food values(null, #{foodName}, #{foodExplain}, #{foodImg}, #{foodPrice}, #{businessId}, #{remarks}, #{stock},0)")
	public Integer addFood(Food food);


	@Select("SELECT * FROM food WHERE foodName LIKE CONCAT('%', #{keyword}, '%')")
	public List<Food> searchFoodByKeyword(@Param("keyword") String keyword);
	@Update("update food set foodName=#{foodName},foodExplain=#{foodExplain},foodImg=#{foodImg},foodPrice=#{foodPrice},stock=#{stock} where foodId=#{foodId}")
	public int updateFood(Food food);
	
	@Update("UPDATE food SET stock = stock - #{quantity}, version = version + 1 WHERE foodId = #{food.foodId} AND version = #{food.version}")
    public Integer updateStock(@Param("food") Food food, @Param("quantity") Integer quantity);
	
	@Delete("delete from food where foodId=#{foodId} and businessId=#{businessId}")
	public int deleteFood(Integer foodId, Integer businessId);
	
	

}